package com.example.springblog.config;

import com.example.springblog.interceptor.LoginInterceptor;
import org.aopalliance.intercept.Interceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Configuration//这个注释
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;

    private final List excludes = Arrays.asList(
            "/**/*.html",
            "/blog-editormd/**",
            "/css/**",
            "/js/**",
            "/favicon.ico", // 放行前端图标资源的请求路径
            "/error",  // 放行当找不到资源时，默认请求的、error路径
            "/pic/**",//上边这些应该都是浏览器样式相关的代码
            "/user/login"//这个是访问后端接口的——登录接口，有必要过滤出来，不被拦截
    );

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")//添加所有路径，进行屏蔽
                .excludePathPatterns(excludes);//排除一些必要路径
    }
}
